package cs236369.hw5.axis2.ypages;

import java.io.IOException;
import java.util.Properties;

import cs236369.hw5.util.ResourceLoader;

public class YellowPagesConf
{
	private final static String PATH = "yellow_pages.properties";
	private final static String SERVICE_KEY = "cs236369.hw5.axis2.ypages.service";
	private final static String CLIENT_KEY = "cs236369.hw5.axis2.ypages.client";
	protected final static String ERR_MSG = "was not able to initialize the properties";

	private static String service = null;
	private static String client = null;

	/**
	 * this method will load the yellow pages configuration from file
	 * 
	 * @throws IOException when properties can't be load, or file doesn't exists
	 */
	public static void initialize() throws IOException
	{
		try
		{
			Properties p = new Properties();
			p.load(ResourceLoader.getResourceAsStream(PATH));
			service = p.getProperty(SERVICE_KEY);
			client = p.getProperty(CLIENT_KEY);
		}
		catch (IOException e)
		{
			throw new IOException(ERR_MSG, e);
		}
	}

	public static String getService() throws IOException
	{
		if (null == service)
		{
			throw new IOException(ERR_MSG);
		}
		return service;
	}

	public static String getClient() throws IOException
	{
		if (null == client)
		{
			throw new IOException(ERR_MSG);
		}

		return client;
	}

}
